#ifndef _BufferSerializer_h_
#define _BufferSerializer_h_

#include "StandardSerializer.h"
#include "Serializable.h"
#include "RecordSerializer.h"
#include <string>

using namespace common;

namespace persist
{
class BufferSerializer : public StandardSerializer
{
protected:
	void *buffer;
	unsigned m_size, m_max_size;
	bool bOpen;

	unsigned id_count;

protected:
	
	virtual void serialize(void* data, size_t size);
//construct or flush object's data from / to the storage
	virtual void fill(Persistent* _persistent);
//
	//allocate a chunk of storage by identifier and return the given name
	virtual std::string allocate(const Identifier& _id);
//	virtual void deallocate(const Identifier& _id);
public:
	virtual bool open(const std::string& fname, Persistor::Mode m = READ){return false;}
	virtual void close(){};
	virtual void clear(){};
	virtual bool isOpen(){return bOpen;}

public:
	//factory
	static BufferSerializer* __stdcall Create();

	BufferSerializer();
	virtual ~BufferSerializer();

	//
	void bufferOpen(Persistor::Mode _mode, void* mem, unsigned max_size);
	void bufferClose(unsigned& size);
	
};
} //namespace

#endif